home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / listview.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  301 lines

  1. head    1.4;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.4; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.4
  10. date    98.01.13.20.01.07;    author dlorre;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    97.07.14.04.20.33;    author dlorre;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    96.08.28.20.04.22;    author dlorre;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @Oui.lib -- Object User Interface
  32. Projet créé en 1994
  33. Auteur: Dominique Lorre
  34. @
  35.  
  36.  
  37. 1.4
  38. log
  39. @now uses MakeVisible
  40. @
  41. text
  42. @// $Id: listview.cc 1.3 1997/07/14 04:20:33 dlorre Exp dlorre $
  43. #include <exec/lists.h>
  44. #include <exec/libraries.h>
  45. #include <libraries/gadtools.h>
  46.  
  47. #include "gadgets/listview.h"
  48. #include "gadgetlist.h"
  49. #include "slist.h"
  50. #include <proto/exec.h>
  51. #include <proto/gadtools.h>
  52. #include <clib/alib_protos.h>
  53.  
  54. // ========================================================================
  55. // ==========================  LIST CLASS =================================
  56. // ========================================================================
  57.  
  58. listview::listview(gadgetlist *gl,
  59.            void (window::*func)(gadget *, unsigned long, unsigned short),
  60.            const char *title,
  61.            unsigned long place,
  62.            nlist *liste,
  63.            unsigned short top,
  64.            unsigned short sel,
  65.            short readonly,
  66.            unsigned short swidth,
  67.            Gadget *showsel) : gadget(gl, func)
  68. {
  69. BOOL badinit = FALSE ;
  70. nlink_iter it(liste) ;
  71.  
  72.     underkey(title) ;
  73.     count = 0 ;
  74.     l = new List ;
  75.     if (l) {
  76.         NewList(l) ;
  77.         while ((sl = it++) && !badinit) {
  78.             if (n = new Node) {
  79.                 n->ln_Name = sl->label ;
  80.                 AddTail(l, n) ;
  81.                 count++ ;
  82.             }
  83.             else
  84.                 badinit = TRUE ;
  85.         }
  86.         if (badinit) {
  87.             n = l->lh_Head ;
  88.             while (n->ln_Succ) {
  89.                 c = n->ln_Succ ;
  90.                 Remove(n) ;
  91.                 delete n ;
  92.                 n = c ;
  93.             }
  94.             delete l ;
  95.             l = NULL ;
  96.         }
  97.     }
  98.     if (l) {
  99.         if (sel != ~0) cursel = sel ; else cursel = -1 ;
  100.         curtop = top ;
  101.         gl->ng->ng_Flags = place ;
  102.         gl->ng->ng_GadgetText = (UBYTE *)title ;
  103.         gad = gl->gad = CreateGadget(LISTVIEW_KIND, gl->gad, gl->ng,
  104.             GTLV_Labels,        l,
  105.             GTLV_Top,           top,
  106.             GTLV_MakeVisible,   top,
  107.             GTLV_Selected,      sel,
  108.             GTLV_ReadOnly,      readonly,
  109.             GTLV_ScrollWidth,   swidth,
  110.             GTLV_ShowSelected,  showsel,
  111.             GT_Underscore,  '_',
  112.             TAG_END) ;
  113.     }
  114. }
  115.  
  116. listview::~listview()
  117. {
  118.     if (l) {
  119.         n = l->lh_Head ;
  120.         while (n->ln_Succ) {
  121.             c = n->ln_Succ ;
  122.             Remove(n) ;
  123.             delete n ;
  124.             n = c ;
  125.         }
  126.         delete l ;
  127.         l = NULL ;
  128.     }
  129. }
  130.  
  131. void listview::set(unsigned short top, unsigned short sel)
  132. {
  133.     if (top != -1) curtop = top ;
  134.     cursel = sel ;
  135.     GT_SetGadgetAttrs(gad, w, NULL,
  136.         GTLV_Top,           curtop,
  137.         GTLV_MakeVisible,   curtop,
  138.         GTLV_Selected,      cursel,
  139.         TAG_DONE) ;
  140. }
  141.  
  142. void listview::reset(nlist *liste, unsigned short top, unsigned short sel)
  143. {
  144. BOOL badinit = FALSE ;
  145. nlink_iter it(liste) ;
  146.  
  147.     count = 0 ;
  148.     GT_SetGadgetAttrs(gad, w, NULL,
  149.         GTLV_Labels,    ~0,
  150.         TAG_DONE) ;
  151.     if (l) {
  152.         n = l->lh_Head ;
  153.         while (n->ln_Succ) {
  154.             c = n->ln_Succ ;
  155.             Remove(n) ;
  156.             delete n ;
  157.             n = c ;
  158.         }
  159.         delete l ;
  160.         l = NULL ;
  161.     }
  162.     l = new List ;
  163.     if (l) {
  164.         NewList(l) ;
  165.         while ((sl = it++) && !badinit) {
  166.             if (n = new Node) {
  167.                 n->ln_Name = sl->label ;
  168.                 AddTail(l, n) ;
  169.                 count++ ;
  170.             }
  171.             else
  172.                 badinit = TRUE ;
  173.         }
  174.         if (badinit) {
  175.             n = l->lh_Head ;
  176.             while (n->ln_Succ) {
  177.                 c = n->ln_Succ ;
  178.                 Remove(n) ;
  179.                 delete n ;
  180.                 n = c ;
  181.             }
  182.             delete l ;
  183.             l = NULL ;
  184.         }
  185.     }
  186.     if (l) {
  187.         if (top != -1) curtop = top ;
  188.         if (sel != ~0) cursel = sel ; else cursel = -1 ;
  189.         GT_SetGadgetAttrs(gad, w, NULL,
  190.             GTLV_Labels,        l,
  191.             GTLV_Top,           top,
  192.             GTLV_MakeVisible,   top,
  193.             GTLV_Selected,      sel,
  194.             TAG_DONE) ;
  195.     }
  196. }
  197.  
  198.  
  199.  
  200. void listview::keystroke(BOOL shifted)
  201. {
  202.     if (shifted) {
  203.         if (cursel)
  204.             cursel-- ;
  205.     }
  206.     else {
  207.         if (cursel < count-1)
  208.             cursel++ ;
  209.     }
  210.     if (GadToolsBase->lib_Version >= 39) {
  211.         GT_GetGadgetAttrs(gad, w, NULL,
  212.             GTLV_Top,       &curtop,
  213.             TAG_DONE) ;
  214.     }
  215.     set(curtop, cursel) ;
  216.     gadget::action(NULL, cursel) ;
  217. }
  218. void listview::action(unsigned long classe, unsigned short code)
  219. {
  220.     cursel = code ;
  221.     gadget::action(classe, code) ;
  222. }
  223. @
  224.  
  225.  
  226. 1.3
  227. log
  228. @*** empty log message ***
  229. @
  230. text
  231. @d1 1
  232. a1 1
  233. // $Id: listview.cc 1.2 1996/08/28 20:04:22 dlorre Exp dlorre $
  234. d65 1
  235. d93 1
  236. a93 1
  237.     if (sel != -1) cursel = sel ;
  238. d95 3
  239. a97 2
  240.         GTLV_Top,       top,
  241.         GTLV_Selected,  sel,
  242. d149 4
  243. a152 3
  244.             GTLV_Labels,    l,
  245.             GTLV_Top,       top,
  246.             GTLV_Selected,  sel,
  247. @
  248.  
  249.  
  250. 1.2
  251. log
  252. @bug affichage dans keystroke (count pour count-1)
  253. @
  254. text
  255. @d1 1
  256. a1 1
  257. // $Id$
  258. d9 3
  259. a11 3
  260. #include <cxxproto/exec.h>
  261. #include <cxxproto/gadtools.h>
  262. #include <cclib/alib_protos.h>
  263. d19 1
  264. a19 1
  265.            STRPTR title,
  266. d61 1
  267. a61 1
  268.         gl->ng->ng_GadgetText = title ;
  269. @
  270.  
  271.  
  272. 1.1
  273. log
  274. @Initial revision
  275. @
  276. text
  277. @d1 1
  278. d3 1
  279. d9 3
  280. a11 15
  281.  
  282. extern "C" {
  283. extern struct ExecBase *SysBase;
  284. void AddTail( struct List *list, struct Node *node );
  285. void Remove( struct Node *node );
  286. #include <pragmas/exec_pragmas.h>
  287.  
  288. extern struct Library *GadToolsBase ;
  289. struct Gadget *CreateGadget( unsigned long kind, struct Gadget *gad,
  290.         struct NewGadget *ng, Tag tag1, ... );
  291. void GT_SetGadgetAttrs( struct Gadget *gad, struct Window *win,
  292.         struct Requester *req, Tag tag1, ... );
  293. #include <pragmas/gadtools_pragmas.h>
  294. void NewList( struct List *list );
  295. }
  296. d163 1
  297. a163 1
  298.         if (cursel < count)
  299. d165 5
  300. @
  301.